﻿var checkMixin = {
    data: function () {
        return {
            products: [],
            amountAndOperatorSetting:[],
            isVirtual: 0, // 0 正常; 1: 虚拟, 2: 携号转网
            callFeeMaintenanceInfo: {},
            isMaintenance: false,
            showCallFeeMaintenanceModalMark: false,
            slowChargeAllCloseMark: false
        }
    },
    created: function () {
        var self = this;
        self.getProduct();
    },
    filters: {
        formatDate1: function (v) {
            var a = new Date(v);
            return getTwo(a.getMonth() + 1) + '-' +  getTwo(a.getDate()) + ' ' + getTwo(a.getHours()) + ':' + getTwo(a.getMinutes());
        }
    },
    methods: {
        checkMobileVirtualOrTrans: function() {
            var self = this;
            if (self.isVirtual > 0) {
                return  self.isVirtual === 1 ? "虚拟号码无法充值" : "携号转网号码无法充值"
            }
            return '';
        },
        //检查手机号是否有效
        checkMobileLoc: function () {
            var self = this;
            axios({
                method: 'get',
                url: "/mpayment/product/findByPhone",
                params: {
                    action: "mobileInfo",
                    phone: self.inputNumber
                }
            })
                .then(function (response) {
                    var json = response.data;
                    if (json.code === "0") {
                        self.areaText = json.data.province + ' ' + json.data.city + ' ' +json.data.operators;
                        self.$nextTick(function () {
                            self.formatChooseList(json.data.list)
                        })
                    }
                })
                .catch(function(error) {

                });
        },
        formatChooseList: function (obj) {
            console.log(obj)
            var self = this;
            list = obj;
            // var list = self.currentNavIndex === 1 ? self.quickChooseList : self.chooseList;
            var slowChargeAllClose = true;
            list.forEach(function(item) {
                Vue.set(item, 'isClose', item.status !== 1)
                if (self.currentNavIndex === 0 && !item.isClose) {
                    slowChargeAllClose = false;
                }
            })
            if (self.currentNavIndex === 1) {
                self.quickChooseList = list;
            } else {
                self.chooseList = list;
                self.slowChargeAllCloseMark = slowChargeAllClose;
            }
            var canPayItem = list.find(function(item) {
                return !item.isClose
            })
            if (canPayItem) {
                self.currentPayItem = canPayItem;
            } else {

                self.currentPayItem = '';
            }
            self.initSpecialChannel();
        },
        getProduct: function () {
            var self = this;

            axios({
                method: 'get',
                url: "/mpayment/product/findAll",
            })
            .then(function (response) {
                if (response.data.code == "0") {
                    self.products = response.data.data;
                    self.amountAndOperatorSetting = response.data.data;
                    console.log(self.products)
                }
            });
        },
        checkAmountValidBySetting: function (item) {
            var self = this;
            if (item.isClose) {
                return false;
            }
            if (self.isMaintenance) {
                return false;
            }
            return true;
        }
    }
}
function getTwo(n) {
    return n < 10 ? ('0' + n) : n;
}
